package XML;

import java.io.*;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

public class UserClient {
    public static void main(String[] args) {
        Socket socket = null;
        ObjectOutputStream writer = null;
        BufferedReader reader = null;
        try {
            socket = new Socket(InetAddress.getLocalHost(), 9999);
            reader = new BufferedReader(new InputStreamReader(System.in));
            System.out.print("璇疯緭鍏ョ敤鎴峰悕锛�");
            String username = reader.readLine();
            System.out.print("璇疯緭鍏ュ瘑鐮侊細");
            String password = reader.readLine();
            User user = new User(username, password);
            writer = new ObjectOutputStream(socket.getOutputStream());
            writer.writeObject(user);
            writer.flush();

            reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            String content = reader.readLine();
            System.out.println(content);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (writer != null) {
                    writer.close();
                }
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
